package com.alfayun.fiscalriskanalysis.indicatorspec;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.alfayun.fiscalriskanalysis.another.type.ScriptType;
import com.alfayun.fiscalriskanalysis.util.IdsConverter;

@Entity
@Table(name = "alert_spec")
public final class AlertSpec {

	@Column(name = "alert_spec_id", updatable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	private Integer id;
	public String name;
	public ScriptType type;
	public String script;
	public String message;
	public String javaFunctionName;
	@Convert(converter = IdsConverter.class)
	public List<Integer> javaFunctionParams;//measure_ids
	public Integer indicatorSpecId;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public static AlertSpec newAlertSpec(AlertSpecRepository repository, AlertSpec alertSpec) {
		alertSpec.id = 0;

		return repository.save(alertSpec);
	}

}
